/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dnstry;

/**
 *
 * @author Claudiu
 */
public class DnsHeader {

   int headerSize =12;
   byte [] headerContent;
   byte [] id;//byte 0 & 1
   byte [] flags;//byte 2 & 3
   byte [] questionCount;//byte 4 & 5
   byte [] answerCount;//byte 6 & 7
   byte [] nameServerCount;//byte 8 & 9
   byte [] additionRecordCount;//byte 10 & 11

   public DnsHeader( byte [] _headerContent)
   {
       headerContent= _headerContent;
   }
   public DnsHeader ()
   {
       headerContent = new byte[100];
        for ( int i = 0 ;i < headerSize ; i++)
        {
            headerContent[i]= 0x00;
        }

   }
   public void setId()
   {
        headerContent[0]=2;
        headerContent[1]=1;
   }
   public void setFlags(boolean inverse)
   {
       if(inverse)
       {
        headerContent[2]=8;}
       else
       {
        headerContent[2]=0;}
        headerContent[3]=0;
   }
   public void setQuestionCount()
   {
        headerContent[4]=0;
        headerContent[5]=1;
   }
   public void setAswerCount ()
   {
        headerContent[6]=0;
        headerContent[7]=0;
   }
   public void setAuthorityCount()
   {
        headerContent[8]=0;
        headerContent[9]=0;
   }
   public void setNameserverCount()
   {
        headerContent[10]=0;
        headerContent[11]=0;
   }
   public void setAdditionalCount()
   {
        headerContent[2]=0;
        headerContent[3]=0;
   }
   public byte[] getHeaderContent()
   {
        return headerContent;
   }
   public void buildHeader(boolean inverse)
    {
        setId();
        setFlags(inverse);
        setQuestionCount();
        setAswerCount();
        setAuthorityCount();
        setNameserverCount();
        setAdditionalCount();
   }

}